package com.dyrj.pig.service.impl;


import com.dyrj.base.system.user.model.SysUser;
import com.dyrj.component.properties.UploadProperties;
import com.dyrj.constant.SysFrameConst;
import com.dyrj.pig.bean.TYskPay;
import com.dyrj.pig.dao.TYskPayMapper;
import com.dyrj.pig.service.TYskPayService;
import com.dyrj.utils.UUIDUtil;
import com.dyrj.vo.PageResultMsg;
import com.dyrj.vo.ResultMsg;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.log4j.Log4j2;
import org.apache.shiro.SecurityUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

/**   
 * @Title: TaskServiceImpl.java 
 * @Package com.dyrj.base.system.user.service.impl
 * @Description: ()
 * @author   
 * @date 2019年4月13日 下午11:30:23
 * @version V1.0   
 */
@Service
@Log4j2
public class TYskPayServiceImpl implements TYskPayService {


    @Resource
	private TYskPayMapper tYskPayMapper;

    @Resource
    private UploadProperties uploadProperties;

    private static String triggerPrefixName = "trigger_";

	@Override
	public PageResultMsg table(TYskPay record) {
        SysUser loginUser = (SysUser) SecurityUtils.getSubject().getSession().getAttribute(SysFrameConst.SYSTEM_USER);
//		record.setUserid(loginUser.getAccount());
		PageInfo<TYskPay> list = PageHelper.startPage(record.getOffset(), record.getLimit()).doSelectPageInfo(() -> tYskPayMapper.selectList(record));
		return new PageResultMsg(SysFrameConst.ResultCode.SUCCESS.CODE, list.getTotal(), list.getList());
	}


	@Override
	public ResultMsg add(TYskPay record) {
        String msg = "";
        SysUser loginUser = (SysUser) SecurityUtils.getSubject().getSession().getAttribute(SysFrameConst.SYSTEM_USER);
        record.setId(UUIDUtil.uuid());
        record.setInsertime(new Date());
        record.setUpdatetime(new Date());
        record.setUserid(loginUser.getAccount());

        try {
            tYskPayMapper.insertSelective(record);

        } catch (Exception e) {
        	e.printStackTrace();
            msg = e.getMessage();
        }

        return new ResultMsg(SysFrameConst.ResultCode.SUCCESS.CODE, SysFrameConst.ResultCode.SUCCESS.MESSAGE+msg);
	}



	@Override
	public TYskPay info(String id) {
		TYskPay tYskPay = tYskPayMapper.selectByPrimaryKey(id);
		return tYskPay;
	}
	
	public ResultMsg update(TYskPay record) {
        String msg = "";
        try {
//            TYskPay record_db = tYskPayMapper.selectByPrimaryKey(record.getId());
            tYskPayMapper.updateByPrimaryKeySelective(record);
        } catch (Exception e) {
            e.printStackTrace();
            msg = e.getMessage();
        }

		return new ResultMsg(SysFrameConst.ResultCode.SUCCESS.CODE, SysFrameConst.ResultCode.SUCCESS.MESSAGE + msg);
	}
	
	@Override
	public ResultMsg delete(String id) {
		tYskPayMapper.deleteByPrimaryKey(id);
		return new ResultMsg(SysFrameConst.ResultCode.SUCCESS.CODE, SysFrameConst.ResultCode.SUCCESS.MESSAGE);
	}

}
